﻿using AllServer.Share;
using Furion.DependencyInjection;
using Grpc.Net.Client;
using MagicOnion.Client;

namespace AllServer.GrpcClient.Account
{
    public interface IAccountGrpcClient
    {
        Task<bool> IsMember(int memberId);

        Task<MemberInfo> GetMember(string userCode);
    }

    public class AccountGrpcClient : IAccountGrpcClient, ITransient
    {
        public async Task<MemberInfo> GetMember(string userCode)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:7187");
            var memberGrpc = MagicOnionClient.Create<IMemberGrpcService>(channel);
            return await memberGrpc.GetMember(userCode);
        }

        public async Task<bool> IsMember(int memberId)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:7187");
            var memberGrpc = MagicOnionClient.Create<IMemberGrpcService>(channel);
            return await memberGrpc.IsMember(1);
        }
    }
}
